<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="lushu">
		<title>加油站销售报表</title>
		<script type="text/javascript" language="javascript" src="../script/common.js"></script>
		<script type="text/javascript" language="javascript" src="../script/common_stat.js"></script>
		<script type="text/javascript" language="javascript">
			var Page;
			function initPageElements(){
				Page.statSets = [StatClass.Org];
				Page.tradeType = Constants.TRADE_TYPE_CARD_CONSUME;
				Page.accountType = [AccountType.FUND,AccountType.POINT];
				
				Page.tradeTypeSpec = function(temp,orgLevel){
					temp.measures = {realAmount:"实际金额",volumn:"油量(升)",count:"交易数"};
					temp.dimensions.accountType = "帐户类型";
					temp.dimensions.goodsCategory = "商品种类";
					if (orgLevel==Constants.ORG_LEVEL_HQ)
						temp.defaultMeasure = {realAmount:true};
					else{
						temp.defaultMeasure = {realAmount:true,volumn:true,count:true};
						temp.defaultHorizon.goodsCategory = true;
						temp.defaultHorizon.tradeStatus = true;
					}
					setOrgConf(temp,orgLevel);
				};
				
				Page.initPivot = function(){
//					Page.benDaiBen = new Pivot("benDaiBen",Page.sql);
//					Page.benDaiBen.setPivotHead('pivotTitle','加油站销售报表 - 本地交易报表');
//					_initPivot(Page.benDaiBen,PivotPage.CrosstabConf.getClearingResultConf());
//					
//					Page.benDaiTa = new Pivot("benDaiTa",Page.sql);
//					Page.benDaiTa.setPivotHead('pivotTitle','加油站销售报表 - 本代它交易报表');
//					_initPivot(Page.benDaiTa,PivotPage.CrosstabConf.getClearingResultConf());
					
					Page.clearingPivot = new Pivot("clearingPivot",Page.sql);
					Page.clearingPivot.setPivotHead('pivotTitle','加油站销售报表 - 已清分交易报表');
					Page.clearingPivot.setPivotHead('statClass','已清分交易报表');
					_initPivot(Page.clearingPivot,PivotPage.CrosstabConf.getClearingResultConf());
					
					Page.dealedTrade = new Pivot("dealedTrade",'dealed_error_trade');
					Page.dealedTrade.setPivotHead('pivotTitle','加油站销售报表 - 已处理异常交易报表(未清分)');
					Page.dealedTrade.setPivotHead('statClass','已处理异常交易报表(未清分)');
					_initPivot(Page.dealedTrade,PivotPage.CrosstabConf.getDealedTradeConf());
					
					Page.ppsTrade = new Pivot("ppsTrade",'ppstrade_station');
					Page.ppsTrade.setPivotHead('pivotTitle','加油站销售报表 - 异常交易报表');
					Page.ppsTrade.setPivotHead('statClass','异常交易报表');
					var conf = PivotPage.CrosstabConf.getPpsTradeConf();
					setOrgConf(conf,Page.orgSpec.LEVEL);
					Page.ppsTrade.initConf(conf);
				}
				
				Page.showPiovt = function(){
					var now = Format.today(true);
					//下面两个报表合并为一个
					//_showClearingPivot(Page.benDaiBen,StatClass.Acquirer,now);
					//_showClearingPivot(Page.benDaiTa,StatClass.BenDaiTa,now);
					_showPivot(Page.clearingPivot,now);
					
					//设置截取时间
					//_showPivot(Page.dealedTrade,now);
					Page.dealedTrade.param = PivotPage._getParam();
					PivotPage.setOrg(Page.dealedTrade.param,'org');
					var cutoffTime = DWR.syncCall('clearingService.getLatestFinishedClearedTime');
					if (cutoffTime)
						Page.dealedTrade.param.cutoffTime = Format.timeRender(cutoffTime);
					Page.dealedTrade.setPivotHead('statTime',now);
					Page.dealedTrade.setPivotHead('beginTime',Page.dealedTrade.param.beginDate);
					Page.dealedTrade.setPivotHead('endTime',Page.dealedTrade.param.endDate);
					Page.dealedTrade.refresh();
					
					_showPivot(Page.ppsTrade,now);
				}
			}
			function setOrgConf(temp,orgLevel){
				switch(orgLevel){
					case Constants.ORG_LEVEL_HQ:
						temp.defaultHorizon.org = {p200:true};
						break;
					case Constants.ORG_LEVEL_PROVINCE:
						temp.defaultHorizon.org = {p500:true};
						break;
					case Constants.ORG_LEVEL_CITY:
						temp.defaultHorizon.org = {p700:true};
						break;
				}
			}
			function _initPivot(pivot,conf){
				Page.tradeTypeSpec(conf,Page.orgSpec.LEVEL);
				pivot.initConf(conf);
			}
			
			function _showPivot(pivot,now){
				pivot.param = PivotPage._getParam();
				PivotPage.setOrg(pivot.param,'org');
				pivot.setPivotHead('statTime',now);
				pivot.setPivotHead('beginTime',pivot.param.beginDate);
				pivot.setPivotHead('endTime',pivot.param.endDate);
				pivot.refresh();
			}
			function _showClearingPivot(pivot,statClass,now){
				pivot.param = PivotPage._getParam();
				Page.orgSpec.setOrgnizations(statClass,pivot.param);		//设置查询的机构参数
				pivot.setPivotHead('statTime',now);
				pivot.setPivotHead('statClass',Common.getText('stat_class',statClass));
				pivot.setPivotHead('beginTime',pivot.param.beginDate);
				pivot.setPivotHead('endTime',pivot.param.endDate);
				pivot.refresh();
			}
		</script>
	</head>
	<body onload="PivotPage.init();" >
		<div class="nav"><div id="nav">&nbsp;</div></div>
		<div id="queryView" class="form">
			<div class="formTitle">加油站销售报表：查询条件</div>
			<form id="statForm" name="statForm">
				<table width="100%" cellspacing="0" cellpadding="4">
					<tr>
						<td colspan="2">
							<label>报表类型</label> 
							<span id="statClass"></span>
						</td>
					</tr>
				</table>
				<div id="stat_btn"></div>
			</form>
		</div>
		<!--统计结果显示部分-->
		<div id="pivotView" style="display:none;">
		<!--
			<div id="benDaiBen"></div>
			<div id="benDaiTa"></div>
		-->
			<div id="clearingPivot"></div>
			<div id="dealedTrade"></div>
			<div id="ppsTrade"></div>
		</div>
	</body>
</html>
